 /*	
 *				
 *					ISNW ---- It is a war.It is not warcraft!
 *
 *
 *					Author:					zhoukeli(haxixi_keli)
 *					Filename:				ISkinned.h
 *					CreateTime:				2008/12/19
 *					ModifyTime:				2008/12/19
 *
 */

#ifndef __ISNW_I_SKINNEDMESH_H__
#define __ISNW_I_SKINNEDMESH_H__

#include "IAnimateMesh.h"
#include "matrix4.h"
#include "isnwString.h"
#include "quaternion.h"

namespace ISNW
{
namespace scene
{
	class ISkinnedMesh : public IAnimateMesh
	{
	public:
		struct weight
		{
			//! buffer id
			u32 buffer_id;
			//! vertex id
			u32 vertex_id;
			//! weight percent 0~1
			f32 strength;

			//! relative vertex 's pos and normal
			core::vector3df orig_pos;
			core::vector3df orig_normal;
		};

		struct positionkey
		{
			//! time
			u32 time;
			//! position offset
			core::vector3df position;
		};

		struct scalekey
		{
			//! time
			u32 time;
			//! scale
			core::vector3df scale;
		};

		struct rotationkey
		{
			//!time 
			u32 time;
			//! rotation
			core::quaternionf rotation;
		};

		struct joint
		{
			//! it should have a name
			core::string				name;

			//! position keys
			core::array<positionkey>	positionkeys;
			//! scale keys
			core::array<scalekey>		scalekeys;
			//! rotation keys
			core::array<rotationkey>	rotationkeys;
			
			//! it may have children
			core::array<joint*>			children;
			//! its parent if it has
			joint*						parent;

			//! weights
			core::array<weight>			weights;

			//! local matrix
			core::matrix4f				frametransformmatrix;

			//! global matrix,transform matrix with parent
			core::matrix4f				transformwithparent;

			//! transform matrix,translate,scale,rotation
			core::matrix4f				animatematrix;

			core::matrix4f				animatewithparent;

			u32							lastframe;

			joint():parent(0),lastframe(0){}
		};

	public:
		//! create joint(frame)
		virtual joint* createjoint(joint* parent) = 0;

		//! create positionkey
		virtual positionkey* createpositionkey(joint* j) = 0;

		//! create rotation key
		virtual rotationkey* createrotationkey(joint* j) = 0;

		//! create scale key
		virtual scalekey* createscalekey(joint* j) = 0;

		//! create weight
		virtual weight* createweight(joint* j) = 0;

		//! animate
		virtual void animate(u32 time) = 0;

	};

} // end namespace scene
} // end namespace ISNW
#endif